package com.niit.common.component;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.io.IOException;

/**
 * 使用注解进行统一配置
 * @author yaojianfeng
 */
//@ControllerAdvice
public class AnnoExceptionController {

    /**
     * 出现Io异常的统一处理方法
     * @param ioException
     * @return
     */
    @ExceptionHandler(IOException.class)
    public String processException(IOException ioException, Model model){
        model.addAttribute("name",ioException.getClass().getSimpleName());
        model.addAttribute("message",ioException.getMessage());
        System.out.println(ioException.getMessage());
        System.out.println("添加IO异常处理的业务逻辑");
        return "exception/ioExceptionPage";
    }


    @ExceptionHandler(Exception.class)
    public String processException(Exception exception, Model model){
        model.addAttribute("name",exception.getClass().getSimpleName());
        model.addAttribute("message",exception.getMessage());
        System.out.println(exception.getMessage());
        System.out.println("添加统一异常处理的业务逻辑,比如说记录日志等");
        return "exception/errorPage";
    }
}
